<?php

namespace addons\Flow\common\models;

use Yii;

/**
 * This is the model class for table "{{%addon_flow_workflow}}".
 *
 * @property int $id
 * @property int $status 状态
 * @property string $created_at 创建时间
 * @property string $updated_at 更新时间
 */
class Transition extends \common\models\base\BaseModel
{

    /**
     * {@inheritdoc}
     */
    public static function tableName()
    {
        return '{{%addon_flow_transition}}';
    }

    /**
     * {@inheritdoc}
     */
    public function rules()
    {
        return [
            [['workflow_id', 'start_status_id','end_status_id'], 'required'],
            [['status','created_at', 'updated_at'], 'integer'],
            [['start_status_id','workflow_id','end_status_id'], 'string', 'max' => 50],
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function attributeLabels()
    {
        return [
            'id' => '编号',
            'workflow_id' => '工作流ID',
            'start_status_id' => '开始状态',
            'end_status_id' => '结束状态',
            'status' => '状态',
            'created_at' => '创建时间',
            'updated_at' => '更新时间',
        ];
    }

    public function getWorkflow()
    {
        return $this->hasOne(Workflow::className(), ['id' => 'workflow_id'])->andWhere(['merchant_id'=>Yii::$app->user->identity->merchant_id]);
    }

    public function getStatus()
    {
        return $this->hasOne(Status::className(), ['id' => 'start_status_id'])->andWhere(['merchant_id'=>Yii::$app->user->identity->merchant_id]);
    }
    public function getStatus0()
    {
        return $this->hasOne(Status::className(), ['id' => 'start_status_id'])->andWhere(['merchant_id'=>Yii::$app->user->identity->merchant_id]);
    }
    public function getStatus1()
    {
        return $this->hasOne(Status::className(), ['id' => 'end_status_id'])->andWhere(['merchant_id'=>Yii::$app->user->identity->merchant_id]);
    }
}
